# -*- makefile -*-
# Openswan master makefile
# Copyright (C) 1998-2002  Henry Spencer.
# Copyright (C) 2003-2004  Xelerance Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

PATCHES=linux
# where KLIPS goes in the kernel
# note, some of the patches know the last part of this path
KERNELKLIPS=$(KERNELSRC)/net/ipsec
KERNELCRYPTODES=$(KERNELSRC)/crypto/ciphers/des
KERNELLIBFREESWAN=$(KERNELSRC)/lib/libfreeswan
KERNELLIBZLIB=$(KERNELSRC)/lib/zlib
KERNELINCLUDE=$(KERNELSRC)/include

MAKEUTILS=packaging/utils
ERRCHECK=${MAKEUTILS}/errcheck
KVUTIL=${MAKEUTILS}/kernelversion
KVSHORTUTIL=${MAKEUTILS}/kernelversion-short

SUBDIRS?=lib programs

clean::
	-(cd ${OPENSWANSRCDIR} && $(MAKE) modclean && $(MAKE) mod26clean)
	-${MAKE} -C tests clean

distclean:	clean
	rm -f out.kpatch
	if [ -f umlsetup.sh ]; then source umlsetup.sh; if [ -d "$$POOLSPACE" ]; then rm -rf $$POOLSPACE; fi; fi

install_file_list:
	@for d in $(SUBDIRS) ; \
	do \
		(cd $$d && $(MAKE) --no-print-directory srcdir=${OPENSWANSRCDIR}/$$d/ OPENSWANSRCDIR=${OPENSWANSRCDIR} install_file_list ) || exit 1; \
	done;

# uninstall, as much as possible
uninstall:
	$(MAKE) --no-print-directory install_file_list | egrep -v '(/ipsec.conf$$|/ipsec.d/)' | xargs rm -f

taroldinstall:
	tar --ignore-failed-read -c -z -f oldFreeSWAN.tar.gz `$(MAKE) --no-print-directory install_file_list`

TAGSFILES=$(wildcard include/*.h include/*/*.h lib/lib*/*.c programs/*/*.h programs/*/*.c linux/include/*.h linux/include/openswan/*.h linux/net/ipsec/*.[ch])

tags:	$(TAGSFILES) Makefile.top
	@LC_ALL=C ctags $(CTAGSFLAGS) ${TAGSFILES}

cscope:
	@ls ${TAGSFILES} > cscope.files
	@cscope -b

TAGS:	$(TAGSFILES)
	@LC_ALL=C etags $(ETAGSFLAGS) ${TAGSFILES}

.PHONY: dummy
dummy:

check: checkprograms
	@${MAKE} -C tests check

testlist:
	@${MAKE} --silent --no-print-directory -C tests testlist

version:
	@echo ${IPSECVERSION}

baseversion:
	@echo ${IPSECBASEVERSION}

packagingprep:
	@for spec in packaging/*/openswan.spec.in; do \
		f=$$(basename $$spec .in); d=$$(dirname $$spec); \
		echo $$spec '->' $$d/$$f; \
		sed "s/IPSECBASEVERSION/${IPSECBASEVERSION}/" $$spec > $$d/$$f; \
	done
	echo IPSECBASEVERSION=${IPSECBASEVERSION} > Makefile.ver

distarchive: packagingprep
	git archive --prefix=openswan-${IPSECBASEVERSION}/ -o ${HOME}/rpmbuild/SOURCES/openswan-${IPSECBASEVERSION}.tar.gz HEAD

# USE_ variables determine if features are compiled into Openswan.
# export them so that "make env" can get at them
export USE_IPSECPOLICY USE_IKEPING
export USE_KEYRR USE_KLIPS USE_NETKEY USE_VENDORID
export USE_AGGRESSIVE USE_XAUTH USE_XAUTHPAM
export USE_NAT_TRAVERSAL USE_NAT_TRAVERSAL_TRANSPORT_MODE USE_LDAP
export USE_LIBCURL
export USE_WEAKSTUFF USE_NOCRYPTO USE_EXTRACRYPTO
export USE_TAPROOM USE_OBJDIR
export HAVE_STATSD USE_DYNAMICDNS
export USE_IPSEC_CONNECTION_LIMIT IPSEC_CONNECTION_LIMIT
export USE_LIBNSS USE_FIPSCHECK USE_MODP_RFC5114 USE_NM USE_LABELED_IPSEC
export USE_MAST USE_SAREF_KERNEL
